package com.maiji.cloud.controller.login;

import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.entities.login.Label;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.ReqMetaData;
import com.maiji.cloud.request.login.*;
import com.maiji.cloud.request.shopingmall.FindByIdReqDto;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseMetaResDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.login.*;
import com.maiji.cloud.response.shopingmall.FoodMaterialCollectionResDto;
import com.maiji.cloud.response.shopingmall.GoodsResData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description: 饮食相关模块
 * 
 * @author zhanglr
 * @date 2019年6月14日
 */
@RestController
@RequestMapping("/deitInterface/")
@Api(tags = { "饮食相关模块" })
public class DietController extends BaseController {

	/**
	 * 添加饮食记录
	 * 
	 * @return
	 */
	@PostMapping("addDietLog")
	@ApiOperation(value = "添加饮食记录")
	public BaseResDto addDietLog(@RequestBody AddDietLogResDto addDietLogResDto,
			@RequestHeader("maijiToken") String maijiToken) {
		addDietLogResDto.getData().setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/deit/addDietLog", addDietLogResDto, BaseResDto.class);

	}

	/**
	 * 获取饮食记录
	 * @param getDietLogReqDto
	 * @return
	 * @throws Exception
	 */
	@PostMapping("getDietLog")
	@ApiOperation(value = "获取饮食记录")
	public DietLogResDto getDietLog_query(@RequestBody GetDietLogReqDto getDietLogReqDto,
			@RequestHeader("maijiToken") String maijiToken) {
		getDietLogReqDto.getData().setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/deit/getDietLog", getDietLogReqDto,
				DietLogResDto.class);
	}

	/**
	 * 食材搜索
	 * 
	 * @return
	 */
	@PostMapping("searchFoodMaterial")
	@ApiOperation(value = "食材搜索")
	public FoodTypeLableResDto searchFoodMaterial(@RequestBody SearchFoodMaterialReqDto searchFoodMaterialReqDto,
			@RequestHeader("maijiToken") String maijiToken) {
		searchFoodMaterialReqDto.setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/deit/searchFoodMaterial", searchFoodMaterialReqDto,
				FoodTypeLableResDto.class);
	}

	/**
	 * 获取详情
	 * 
	 * @return
	 */
	@PostMapping("getFoodMaterialDetailById")
	@ApiOperation(value = "获取食材详情")
	public FoodMaterialDetialResDto getFoodMaterialDetailById(@RequestBody BaseDataReqDto<String> baseDataReqDto,
                                                              @RequestHeader("maijiToken") String maijiToken) {
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/deit/getFoodMaterialDetailById", baseDataReqDto, FoodMaterialDetialResDto.class);
	}

	/**
	 * 根据标签ID获取美食推荐食谱列表(登录地区推荐优先)
	 * @param token
	 * @return
	 */
	@ApiOperation(value = "根据标签ID获取美食推荐食谱列表(登录地区推荐优先)")
	@PostMapping("/findAllRecipeByLogin")
	public BaseMetaResDto<List<RecipeResData>> findAllRecipeByLogin(@RequestBody BaseDataReqDto<String> baseReqMetaDto,
                                                                    @RequestHeader("maijiToken") String token) {
		return postForObjectWithToken(token, REST_URL_APPLOGIN + "/deit/findAllRecipeByLogin", baseReqMetaDto,
				BaseMetaResDto.class);
	}

	/**
	 * 根据标签ID[]查询食谱列表
	 * @param baseDataReqDto
	 * @return
	 */
	@ApiOperation(value = "根据标签获ID[]取食谱列表 - 获取全部传[]")
	@PostMapping("/findAllRecipeByLabelIds")
	public BaseMetaResDto<List<RecipeResData>> findAllRecipeByLabelIds(@RequestBody BaseDataReqDto<List<String>> baseDataReqDto) {
        List<String> labelIds = baseDataReqDto.getData();
        ReqMetaData reqMetaData = baseDataReqDto.getMetaData();
        RecipeFindAllReqData findAllReqData = new RecipeFindAllReqData().setLabelIds(labelIds);
        BaseDataReqDto<RecipeFindAllReqData> newBaseDataReqDto = new BaseDataReqDto<>();
        newBaseDataReqDto.setData(findAllReqData).setMetaData(reqMetaData);
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/deit/findAllRecipes", newBaseDataReqDto, BaseMetaResDto.class);
	}

	/**
	 * 根据食材ID获取相关食谱列表
	 * @param baseDataReqDto
	 * @return
	 */
	@ApiOperation(value = "根据食材ID获取相关食谱列表")
	@PostMapping("/findAllRecipesByFoodId")
	public BaseMetaResDto<List<RecipeResData>> findAllRecipesByFoodId(@RequestBody BaseDataReqDto<String> baseDataReqDto,
                                                                       @RequestHeader("maijiToken") String token) {
        return postForObjectWithToken(token, REST_URL_APPLOGIN + "/deit/findAllRecipesByFoodId", baseDataReqDto, BaseMetaResDto.class);
	}

	/**
	 * 根据食谱ID获取食谱详情
	 * @param baseDataReqDto
	 * @return
	 */
	@ApiOperation(value = "根据食谱ID获取食谱详情")
	@PostMapping("/findRecipeById")
	public BaseDataResDto<RecipeResData> findRecipeById(@RequestBody BaseDataReqDto<String> baseDataReqDto,
                                                        @RequestHeader("maijiToken") String token) {
		return postForObjectWithToken(token, REST_URL_APPLOGIN + "/deit/findRecipeById", baseDataReqDto, BaseDataResDto.class);
	}

	/**
	 * 根据食谱名称或别名查询食谱列表
	 * @param baseDataReqDto
	 * @return
	 */
	@ApiOperation(value = "根据食谱名称获取食谱列表（获取全部传空串）")
	@PostMapping("/findAllRecipeByName")
	public BaseMetaResDto<List<RecipeResData>> findAllRecipeByName(@RequestBody BaseDataReqDto<String> baseDataReqDto,
                                                                   @RequestHeader("maijiToken") String token) {
		return postForObjectWithToken(token, REST_URL_APPLOGIN + "/deit/findAllRecipeByName", baseDataReqDto, BaseMetaResDto.class);
	}

	/**
	 * 获取用户收藏食谱列表
	 * 
	 * @param token
	 * @return
	 */
	@ApiOperation(value = "获取用户收藏食谱列表")
	@PostMapping("/findAllRecipeCollection")
	public BaseMetaResDto<List<RecipeResData>> findAllRecipeCollection(@RequestBody BaseDataReqDto baseReqMetaDto,
                                                                       @RequestHeader("maijiToken") String token) {
		return postForObjectWithToken(token, REST_URL_APPLOGIN + "/deit/findAllRecipeCollection", baseReqMetaDto, BaseMetaResDto.class);
	}

	/**
	 * 获取用户收藏食材列表
	 * 
	 * @param baseReqMetaDto
	 * @param token
	 * @return
	 */
	@ApiOperation(value = "获取用户食材列表")
	@PostMapping("foodMaterialCollectionList")
	public FoodMaterialCollectionResDto foodMaterialCollectionList(@RequestBody BaseDataReqDto baseReqMetaDto,
			@RequestHeader("maijiToken") String token) {
		return postForObjectWithToken(token, REST_URL_APPLOGIN + "/deit/foodMaterialCollectionList", baseReqMetaDto,
				FoodMaterialCollectionResDto.class);
	}

    /**
     *  获取食谱列表标签[]
     * @return
     */
    @PostMapping("findAllRecipeLabels")
    @ApiOperation(value = "获取食谱列表标签[]")
    public BaseDataResDto<List<LabelResData>> findAllRecipeLabels(@RequestHeader("maijiToken") String token) {
        BaseDataReqDto<Label> baseDataReqDto = new BaseDataReqDto().setData(new Label().setSource("食谱").setListShow(1));
        return postForObjectWithToken(token, REST_URL_APPLOGIN + "/common/findAllLabelsBySource", baseDataReqDto, BaseDataResDto.class);
    }
	
	   /**
     *获取所有的一级食材列表
     * @return
     */
	@PostMapping("getFoodmaterialTypeLable")
	@ApiOperation(value = "获取所有的一级食材列表")
	public FoodTypeLableResDto getFoodmaterialTypeLable(@RequestHeader("maijiToken") String token){
		return postForObjectWithToken(token, REST_URL_APPLOGIN + "/deit/getFoodmaterialTypeLable", null,
				FoodTypeLableResDto.class);
	}

	/**
	 * 食材收藏/取消收藏
	 * 
	 * @param param
	 * @param token
	 * @return
	 */
	
	@ApiOperation(value = "食材收藏/取消收藏")
	@PostMapping("thumbsfoodMaterial")
	public BaseResDto thumbsfoodMaterial(@RequestBody ThumbsfoodMaterialReqDto param,
			@RequestHeader("maijiToken") String token) {
		return postForObjectWithToken(token, REST_URL_APPLOGIN + "/deit/thumbsfoodMaterial", param, BaseResDto.class);
	}
	
	   /**
     *  食材标签列表
     * @return
     */
    @PostMapping("findAllLabelsBySource")
    @ApiOperation(value = "食材标签列表")
    public BaseDataResDto<List<LabelResData>> findAllLabelsBySource (@RequestHeader("maijiToken") String token) {
    	BaseDataReqDto<Label> param = new BaseDataReqDto<Label>();
    	Label label = new Label();
    	label.setSource("食材");
    	label.setListShow(1);
    	param.setData(label);
    	return postForObjectWithToken(token, REST_URL_APPLOGIN + "/common/findAllLabelsBySource", param, BaseDataResDto.class);
    }

    /**
     *  获取食材相关商品列表
    * @param baseDataReqDto
    * @return
    */
   @PostMapping("findAllGoodsByFoodId")
   @ApiOperation(value = "根据食材ID获取食材相关商品列表")
   public BaseMetaResDto<List<GoodsResData>> findAllGoodsByFoodId(@RequestBody BaseDataReqDto<String> baseDataReqDto,
                                                                          @RequestHeader("maijiToken") String token){
       return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/goods/findAllGoodsByFoodId", baseDataReqDto, BaseMetaResDto.class);
   }

    /**
     *  获取食谱相关商品列表
    * @param baseDataReqDto
    * @return
    */
   @PostMapping("findAllGoodsByFoodIds")
   @ApiOperation(value = "根据食材ID[]获取食谱相关商品列表")
   public BaseMetaResDto<List<GoodsResData>> findAllGoodsByFoodIds(@RequestBody BaseDataReqDto<List<String>> baseDataReqDto,
                                                                          @RequestHeader("maijiToken") String token){
       return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/goods/findAllGoodsByFoodIds", baseDataReqDto, BaseMetaResDto.class);
   }

}
